package com.senmiao.ssm.exception;

import com.senmiao.ssm.util.Result;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class MyExceptionHandler {

    @ExceptionHandler({UnknownAccountException.class, IncorrectCredentialsException.class,AuthenticationException.class})
    @ResponseBody
    public Result unknownAccountException(Exception e){
        e.printStackTrace();
        return new Result<>().code(403).msg("用户名或密码错误");
    }

    @ExceptionHandler({AuthorizationException.class})
    @ResponseBody
    public Result authorizationException(AuthorizationException e){
        e.printStackTrace();
        return new Result<>().code(403).msg("权限不足");
    }
}